package com.stx.boke.servlet;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.stx.boke.dao.UserDao;
import com.stx.boke.dao.impl.UserDaoImpl;
import com.stx.boke.entity.User;
import com.stx.boke.tool.GetTime;

/**
 * Servlet implementation class RegistUser
 */
public class RegistUser extends HttpServlet {
	private static final long serialVersionUID = 1L;
	private UserDao ud = new UserDaoImpl();   
    /**
     * @see HttpServlet#HttpServlet()
     */
    public RegistUser() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		request.setCharacterEncoding("utf-8");
		response.setCharacterEncoding("utf-8");
		
		String uname = request.getParameter("uname");
		String password = request.getParameter("password");
		String email = request.getParameter("email");
		String blogname= request.getParameter("blogname");
		
		//申请时间，我这里给你一个骚的方法
		String createtime = GetTime.getTime();//获得服务器时间 例如：“2012-10-26”
		
		//依然是new一个User对象传值给方法撒
		User user = new User();
		user.setUname(uname);
		user.setCreatetime(createtime);
		user.setPassword(password);
		user.setEmail(email);
		user.setBlogname(blogname);
		
		int add = ud.addUser(user);//这里调用addUser()方法
		if(add==1){
			//这里返回值肯定是1，不是1就错了
			System.out.println("注册成功！");
			response.sendRedirect("/kqblog/jsp/me.jsp");
		}else{
			System.out.println("注册失败！");
			response.sendRedirect("/kqblog/jsp/register.jsp");
			
		}
		
		
		
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		this.doGet(request, response);//这个也就不说了！
	}

}
